<template>
	<view class="">
		<view class="uni-status-bar"></view>
		<view class="card">
			<view class="item" @click="addressCopy(data.InvitedURL)">
				<text class="item-label">{{$t('my.invite.link')}}</text>
				<view class="item-right">
					<text class="value">{{data.InvitedURL}}</text>
					<image src="/static/my/copy.png"></image>
				</view>
			</view>
			<view class="item" @click="addressCopy(data.InvitedCode)">
				<text class="item-label">{{$t('my.invite.code')}}</text>
				<view class="item-right">
					<text class="value">{{data.InvitedCode}}</text>
					<image src="/static/my/copy.png"></image>
				</view>
			</view>
		</view>
		<swiper class="swiper" previous-margin="76rpx" next-margin="76rpx" :indicator-dots="true"
			indicator-color='#C0C0C0' indicator-active-color='#E3892A' :circular="true" @change="current">
			<swiper-item class="swiper-item" v-for="(item, index) in carouselsData" :key="index">
				<view class="img-box">
					<posters-share v-if="data.InvitedURL" :poster-id="item.id" :url="item.image"
						:address="data.InvitedURL"></posters-share>
				</view>
			</swiper-item>
		</swiper>
		<view class="btn-box">
			<view class="buttonBg" @click="onSave">{{$t('my.invite.save')}}</view>
		</view>
	</view>
</template>

<script>
	import {
		inviteData
	} from '@/api/user';
	import postersShare from "./components/posters-share.vue";
	export default {
		name: "share",
		data() {
			return {
				backType: '',
				data: {},
				carouselsData: [{
						image: '/static/my/invite1.png',
						id: 'inviteBg1'
					},
					{
						image: '/static/my/invite2.png',
						id: 'inviteBg2'
					},
					{
						image: '/static/my/invite3.png',
						id: 'inviteBg3'
					}
				],
				show: false,
				currentIndex: 0,
				Locale: ''
			}
		},
		created() {
			this.getInviteData();
		},
		onShow() {
			this.Locale = uni.getLocale()
		},
		onLoad(option) {
			this.backType = option.type
		},
		mounted() {
			let time = setTimeout(() => {
				this.show = true;
				clearInterval(time)
			}, 1000)
		},
		computed: {
			inviteImg() {
				var date1 = new Date().getTime()
				return this.data.inviteImg + '?+date=' + date1;
			}
		},
		methods: {
			goBack() {
				if (this.backType == 1) {
					uni.switchTab({
						url: '/pages/home/index'
					})
				} else {
					uni.navigateBack({
						delta: 1,
						animationType: 'pop-out',
						animationDuration: 300
					});
				}
			},
			getInviteData() {
				inviteData().then((res) => {
					this.data = res.data;
				})
			},
			addressCopy(text) {
				var that = this
				uni.setClipboardData({
					data: text,
					success: function() {
						uni.showToast({
							icon: 'success'
						})
					},
					fail: function() {
						uni.showToast({
							icon: 'none',
							title: this.$t('my.copyF')
						})
					}
				});
			},
			current(e) {
				this.currentIndex = e.detail.current;
			},
			saveH5(url) {
				console.log(url, "url")
				var ALink = document.createElement("a");
				ALink.download = '';
				ALink.href = url
				document.body.appendChild(ALink);
				ALink.click();
				ALink.remove();
			},
			onSave() {
				uni.$emit('saveImageToPhotosAlbum', this.carouselsData[this.currentIndex].id);

			},
			onNavigateBack() {
				uni.navigateBack({
					delta: 1
				});
			}
		},
		onNavigationBarButtonTap() {
			uni.navigateTo({
				url: '/pages/my/user-center/invited-record'
			})
		}
	}
</script>

<style scoped lang="scss">
	page {
		height: 100%;
		background: $hb-bg;
	}

	.btn-box {
		margin-top: 80rpx;
		display: flex;
		justify-content: center;
		padding: 0 60rpx;

		.hb-button {
			width: 638rpx;
			border-radius: 43rpx;
		}
	}

	.buttonBg {
		width: 100%;
		height: 80rpx;
		background: $hb-primary-color;
		background-size: cover;
		color: #fff;
		text-align: center;
		line-height: 80rpx;
		font-size: 28rpx;
	}

	.card {
		height: 100%;
		padding-left: 0;
		padding-right: 0;
		border-radius: none;
		background: #fff;

		.item {
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 20rpx 0;
			margin: 0 32rpx;
			border-bottom: 1PX solid $hb-border-color;

			&-label {
				display: block;
				min-width: 200rpx;
				font-size: 28rpx;
				color: $hb-text-color;
			}

			&-right {
				font-size: 28rpx;
				display: flex;
				align-items: center;

				.value {
					word-break: break-all;
					display: -webkit-box;
					-webkit-box-orient: vertical;
					-webkit-line-clamp: 1;
					overflow: hidden;
					color: $hb-title-color;
				}

				image {
					width: 40rpx;
					height: 40rpx;
					flex-shrink: 0;
					margin-left: 16rpx;
				}

				.copy {
					color: $hb-primary-color;
					font-size: 44rpx;
					margin-left: 10rpx;
				}
			}
		}

		.share-title {
			display: block;
			padding: 20rpx 0;
			color: $hb-text-color;
		}

		.share-image {
			width: 90%;
			height: 600rpx;
			margin: 20rpx auto;

			.image {
				display: block;
				width: 100%;
				height: 100%;
			}
		}

		.share-explain {
			background: $hb-bg;
			margin-top: 20rpx;

			.share-explain-title {
				display: block;
				font-size: 28rpx;
				color: $hb-title-color;
			}

			.share-explain-text {
				display: block;
				font-size: 24rpx;
				color: $hb-text-color;
			}
		}
	}

	.swiper {
		height: 786rpx;
		margin-top: 32rpx;

		/deep/.uni-swiper-wrapper {
			overflow: inherit;
		}

		/deep/.uni-swiper-dots {
			height: 6rpx;
			border-radius: none;
			bottom: -32rpx;
		}

		/deep/.uni-swiper-dot {
			width: 20rpx;
			height: 6rpx;
			border-radius: inherit;
		}

		.img-box {
			// width: 552rpx;
			height: 786rpx;
			padding: 0 18rpx;
			box-sizing: border-box;

			.banner {
				width: 100%;
				height: 100%;
			}
		}
	}
</style>
